package demo1;

import java.util.Arrays;

public class Solution {
    public void merge(int[] nums1,int m , int[] nums2, int n){
        int[] array = new int[m+n];
        int p1 = 0;
        int p2 = 0;
        int tem = 0;
        while(p1 < m || p2 < n){
            if(p1 == m){
                tem = nums2[p2];
                p2++;
            }else if(p2 == n){
                tem = nums1[p1];
                p1++;
            } else if(nums1[p1] > nums2[p2]){
               tem = nums2[p2];
               p2++;
           }else{
               tem = nums1[p1];
               p1++;
           }
           array[p1 + p2 - 1] = tem;
        }
        nums1 = array;
    }
    public static void main(String[] args) {
        int[] array1 = {1,2,3,0,0,0};
        int[] array2 = {3,4,5};
        Solution solution = new Solution();
        solution.merge(array1,3,array2,3);
    }
    public void merge1(int[] nums1, int m, int[] nums2, int n) {
        int tem = m;
        for(int i = 0 ; i < n ;i++){
            nums1[tem] = nums2[i];
            tem++;
        }
        Arrays.sort(nums1);
    }
    public int removeDuplicates1(int[] nums) {
      int left = 0 ;
      for(int right = 0 ; right < nums.length; right++){
          if(nums[left] != nums[right]){
              left++;
              nums[left] = nums[right];
          }
      }
      return left + 1;
    }


    public int removeElement(int[] nums, int val){
        int left = 0;
        int right = nums.length;
        while(left < right){
            if(nums[left] == val){
                nums[left] = nums[right];
                right--;
            }else {
                left++;
            }
        }
        return left;
    }
    public int removeElement1(int[] nums, int val) {
      int left = 0;
      for(int right = 0 ; right < nums.length ; right++){
          if(nums[right] != val){
              nums[left] = nums[right];
              left++;
          }
      }
      return left;
    }
}
